<?php defined('SYSPATH') or die('No direct script access.');

class Helper_Index
{
    public static function supplier_single($supplier)
    {
        $content = new View('index/supplier/_supplier_single_tpl');
        $content->supplier = $supplier;
        return $content;        
    }
    
    public static function suppliers_list($suppliers)
    {
        $content = new View('index/supplier/_suppliers_list_tpl');
        $content->suppliers = $suppliers;
        return $content;        
    }
    
    public static function good_single($good, $suppliers = null)
    {
        $content = new View('index/supplier/_good_single_tpl');
        $content->good = $good;
        $content->suppliers = $suppliers;
        return $content;        
    }
    
    public static function goods_list($goods, $suppliers = null)
    {
        $content = new View('index/supplier/_goods_list_tpl');
        $content->goods = $goods;
        $content->suppliers = $suppliers;
        return $content;        
    }
    
    public static function redirect_301($url)
    {
        header('HTTP/1.1 301 Moved Permanently');
        header('Location: '.$url);
        die();
    }
    
    public static function date($date)
    {
        $d = date('d', $date);
        $m = date('m', $date);
        $y = date('Y', $date);
        
        $months = array(
            '01' => 'января',
            '02' => 'февраля',
            '03' => 'марта',
            '04' => 'апреля',
            '05' => 'мая',
            '06' => 'июня',
            '07' => 'июля',
            '08' => 'августа',
            '09' => 'сентября',
            '10' => 'октября',
            '11' => 'ноября',
            '12' => 'декабря',
        );
        
        return $d . ' ' . $months[$m] . ' ' . $y;
    }
    
    public static function pagination($page, $per_page, $count, $url, $first_url)
    {
        if (ceil($count / $per_page) == 1) {
            return '';
        }
        $content = new View('index/_pagination_tpl');
        $content->page     = $page;
        $content->per_page = $per_page;
        $content->count    = $count;
        $content->url      = $url;
        $content->first_url = $first_url;
        return $content;   
    }
    
    public static function anchor_text($text)
    {
        $n = mt_rand(0, 2);
        if ($n == 0) {
            return $text . ' отзывы';
        } else if ($n == 1) {
            return 'Отзывы о ' . $text;
        }
        return $text;
    } 
} 
